/* 通过URLSearchParams构造函数获取要添加的商品 */
let obj = new URLSearchParams(location.search);
let pid = obj.get("pid");
//根据商品接口id添加商品
axios.get(productDetailAPI, {
	params: {
		id: pid
	}
}).then(function(res) {
	let obj = res.data;
	//商品详情数据
	let pObj = obj.data;
	let html = `
						<dl>
							<dt><img src="${pObj.pimg}"><a href="#">了解详情</a></dt>
							<dd>
								<div class="left-bottom">
									<span><i class="iconfont icon-tuihuo"></i>30天退换货</span>
									<span><img src="img/kd.png">全场免运费</span>
								</div>
								<div class="left-bottom">
									<span><i class="iconfont icon-kefu"></i>24X7在线服务</span>
									<span><img src="img/shandian.png">极速上手服务</span>
								</div>
								<div class="left-bottom">
									<span><i class="iconfont icon-rili"></i>价格保障</span>
								</div>
							</dd>
						</dl>
					  `;
	let itemDiv = document.querySelector(".left-content");
	itemDiv.innerHTML = html; //加入购物车

	/* right-bottom */
	let html2 = `
						<h2>配置</h2>
						<h1>${pObj.pdesc}</h1>
						<div class="right-bottom-title">
							<button type="button">13英寸</button>
							<button type="button">15英寸</button>
						</div>
						<div class="total">
							<a href="#">${pObj.pprice}${pObj.pnum}</a>
							<span>加入购物车</span>
						</div>
					  `;
	let rightbottom = document.querySelector(".right-bottom ");
	rightbottom.innerHTML = html2; //加入购物车
	let carAdd = document.querySelector(".total span")
	console.log(carAdd);
	carAdd.onclick = function() {
		//uid  用户id
		// pid  商品id
		// pnum  要添加的商品数量
		let uid = localStorage.getItem("uid");
		let pnumIpt = document.querySelector(".left-content dl dt");
		let pnum = document.querySelector(".right-bottom h1");
		let pnum1 = document.querySelector(".right-bottom .total a");
		axios.get(CartAddAPI, {
			params: {
				uid: uid,
				pid: pid,
				pnum: {
					 pnumIpt,
					 pnum  
				}
			}
		}).then(function(res) {
			let obj = res.data;
			alert(obj.msg);
		});
	}
});
